<template lang="pug">
    skin(@up="up",@down="down",@yes="yes",@back="back",@duringUp="up",@duringDown="down")
        div(class="flex-column h2")
            div(class="flex-column-item")
            div(class="flex-column-item center")
                span(v-if="state=='ready'") 请输入密码:
                span(v-if="state=='fail'") 密码错误！！！
            div(class="flex-column-item center")
                control-password(@submit="submit",ref="cp",v-if="state=='ready'")
                span(@submit="submit",ref="cp",v-if="state=='fail'") 按任意键返回
            div(class="flex-column-item")
</template>

<script>
/** 恢复出厂值输入密码 */
export default {
    data(){
        return { 
            state: 'ready',// 密码错误:fail 密码正确: success
         }
    },
    methods:{
        up(){
          if(this.state == 'ready') {
              this.$refs.cp.up();
          }
          if(this.state == 'fail') {
              this.$router.push('/menu/menu/index?index=5');
          }
        },
        down(){
          if(this.state == 'ready')  {
              this.$refs.cp.down();
          }else if(this.state == 'fail') {
              this.$router.push('/menu/menu/index?index=5');
          }
        },
        yes(){
          if(this.state == 'ready') {
            this.$refs.cp.yes();
          }  
          else if(this.state == 'fail'){
            this.$router.push('/menu/menu/index?index=5');
          } 
        },
        back(){
          if(this.state == 'ready') {
              this.$refs.cp.back();
          }
          else if(this.state == 'fail') {
              this.$router.push('/menu/menu/index?index=5');
          }
        },
        submit(password){
            if(password == "5678"){
                this.$router.push('/advance-setting/doctor1')
            }else{
                this.state = 'fail'
            }
        }
    }
}
</script>

<style>

</style>
